package com.bruce.phoneFlash;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class WelcomeActivity extends AppCompatActivity {

    private Handler mHandler;
    private SharedPreferences sp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        sp = getSharedPreferences("flash", MODE_PRIVATE);
        mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                Intent intent;
                if (!sp.getString("version", "0").equals("1")) {//判断版本号是否相同  默认是1
                    intent = new Intent(WelcomeActivity.this, FirstActivity.class);
                } else {
                    intent = new Intent(WelcomeActivity.this, MainActivity.class);
                }
                startActivity(intent);
                finish();
            }
        };
        Message msg = Message.obtain();
        mHandler.sendMessageDelayed(msg, 1000);
    }

    @Override
    protected void onDestroy() {
        mHandler.removeCallbacksAndMessages(null);
        mHandler = null;
        super.onDestroy();
    }
}
